Skip to content

fix(threads): Keep active-turn runtime errors from ending sessions#1261

Open
Snowy7 wants to merge 1 commit intopingdotgg:mainfrom
Snowy7:feature/runtime-error-session
Open

fix(threads): Keep active-turn runtime errors from ending sessions#1261
Snowy7 wants to merge 1 commit intopingdotgg:mainfrom
Snowy7:feature/runtime-error-session

Conversation

@Snowy7
Copy link

@Snowy7 Snowy7 commented Mar 21, 2026

Summary

Closes #490

This keeps active Codex turns projected as running when a non-terminal runtime.error arrives mid-turn.

Previously, runtime ingestion treated any runtime.error as a terminal session error. In cases like Windows os error 206 (The filename or extension is too long), Codex could continue running in the background while the UI was projected as stopped/errored, leaving the session desynced and no longer stoppable from the UI.

What Changed

  • changed provider runtime ingestion so runtime.error does not force the session into error while the active turn is still running
  • preserved existing terminal lifecycle handling from:
    • turn.completed with failed state
    • session.state.changed with error
    • session.exited
  • added tests covering:
    • runtime.error with no active turn still marks the session as errored
    • runtime.error for the active turn keeps the session running and records the runtime error activity

Why

This is a small reliability fix.

It keeps session state predictable under failure conditions and prevents the UI from desyncing from the actual Codex runtime when a mid-turn exec error is advisory rather than terminal.

Scope

This PR is intentionally narrow and only changes runtime session projection behavior for active-turn runtime.error events.

Testing

  • bun fmt
  • bun lint
  • bun typecheck
  • bun x vitest run apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts

Notes

No UI change screenshots are included because this PR does not change visuals directly.

Note

Keep sessions running when runtime.error arrives during an active turn

Previously, any runtime.error event would transition the session to an error state. Some providers emit advisory runtime errors while still streaming an active turn, so this change prevents premature session termination in that case.

  • In ProviderRuntimeIngestion.ts, a new isActiveTurnRuntimeError flag detects when the error belongs to the currently active turn; the session is only set to error status when this flag is false.
  • The session remains running with activeTurnId unchanged until a terminal lifecycle event arrives.
  • Behavioral Change: runtime.error events tied to the active turn are now recorded in the thread but no longer end the session.
📊 Macroscope summarized af1c65c. 5 files reviewed, 1 issue evaluated, 1 issue filtered, 0 comments posted

🗂️ Filtered Issues

apps/server/src/git/Layers/GitService.ts — 0 comments posted, 1 evaluated, 1 filtered
  • line 79: The error message on line 79 says "output exceeded ${maxOutputBytes} bytes and was truncated." but this error is raised specifically when truncateOutput is false — meaning the output was NOT truncated, an error was thrown instead. The message should say something like "output exceeded ${maxOutputBytes} bytes" without the misleading "and was truncated" clause. [ Posting failed ]

- Treat runtime.error as advisory while an active turn is still running
- Add coverage for active-turn runtime.error and no-turn error mapping
Copilot AI review requested due to automatic review settings March 21, 2026 00:36
@coderabbitai
Copy link

coderabbitai bot commented Mar 21, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2f773489-3203-434b-b9d9-65c5b37b1914

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can disable poems in the walkthrough.

Disable the reviews.poem setting to disable the poems in the walkthrough.

@github-actions github-actions bot added size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Mar 21, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts provider runtime ingestion so non-terminal runtime.error events received during an active turn no longer force the projected session into an error state, preventing UI/runtime desynchronization while the turn is still streaming/running.

Changes:

  • Update runtime.error ingestion to avoid setting session status to error when the error corresponds to the currently active turn.
  • Keep existing terminal handling for turn.completed (failed), session.state.changed (error), and session.exited.
  • Add/adjust tests to cover session projection behavior for runtime.error with and without an active turn.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts Prevents runtime.error from terminally erroring the session while an active turn is still running.
apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts Adds tests for session projection behavior when runtime.error arrives during an active turn.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1133 to +1139
const isActiveTurnRuntimeError =
activeTurnId !== null && (eventTurnId === undefined || sameId(activeTurnId, eventTurnId));

// Some provider/runtime errors are advisory while the active turn continues
// streaming. Keep the projected session runnable until a terminal lifecycle
// event arrives.
if (shouldApplyRuntimeError && !isActiveTurnRuntimeError) {
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new isActiveTurnRuntimeError logic treats runtime.error events with a missing turnId as belonging to the active turn (and therefore not session-terminal). That branch (eventTurnId === undefined while activeTurnId !== null) isn’t covered by the added tests, and it’s an important case because some adapters can emit runtime errors without a turn id. Add a test that starts a turn, emits runtime.error without turnId, and asserts the session remains running while a runtime.error activity is still recorded.

Copilot uses AI. Check for mistakes.
@Snowy7 Snowy7 changed the title Keep active-turn runtime errors from ending sessions fix: Keep active-turn runtime errors from ending sessions Mar 21, 2026
@Snowy7 Snowy7 changed the title fix: Keep active-turn runtime errors from ending sessions fix(web): Keep active-turn runtime errors from ending sessions Mar 21, 2026
@Snowy7 Snowy7 changed the title fix(web): Keep active-turn runtime errors from ending sessions fix(threads): Keep active-turn runtime errors from ending sessions Mar 21, 2026
@github-actions github-actions bot added size:L 100-499 changed lines (additions + deletions). and removed size:M 30-99 changed lines (additions + deletions). labels Mar 21, 2026
@Snowy7 Snowy7 force-pushed the feature/runtime-error-session branch from af1c65c to db3f20f Compare March 21, 2026 14:38
@github-actions github-actions bot added size:M 30-99 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI desync from error

2 participants